import { createStore } from 'vuex';

export default createStore({
    state: {
        login_name: '', // 存储用户名
        login_password: '', // 存储密码


        user: JSON.parse(localStorage.getItem('user')) || null,
//用来存放联系人列表
        contactList: []
    },
    mutations: {
        setLoginName(state, value) {
            state.login_name = value; // 更新用户名
        },
        setLoginPassword(state, value) {
            state.login_password = value; // 更新密码
        },

        setUser(state, user) {
    state.user = user;
  },
  setContactList(state, list) {
    state.contactList = list;
  }
    },
    actions: {
        updateLoginName({ commit }, value) {
            commit('setLoginName', value); // 触发用户名更新
        },
        updateLoginPassword({ commit }, value) {
            commit('setLoginPassword', value); // 触发密码更新
        },
        submitLogin({ state }) {
            // 模拟登录操作，实际项目中这里会调用 API
            console.log('Login submitted:', {
                username: state.login_name,
                password: state.login_password
            });
        },
        
    },
    getters: {
        getLoginName: (state) => state.login_name, // 获取用户名
        getLoginPassword: (state) => state.login_password, // 获取密码

        getUser: (state) => state.user,
        contactList: (state) => state.contactList

    }
});